package com.jlcloud.core.tenant.processor;

import com.jlcloud.core.auto.annotation.AutoEnvPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * 初始化分库分表配置
 *
 * @author By: JlCloud <br>
 * @Package: com.jlcloud <br>
 * @CreateTime: 2024-12-03 21:45 <br>
 * @Copyright: 2021 www.jilianjituan.com Inc. All rights reserved. <br>
 * @Caution 注意：本内容仅限于冀联人力集团内部传阅，禁止外泄以及用于其他的商业目的 <br>
 */
@AutoEnvPostProcessor
public class TenantEnvPostProcessor implements EnvironmentPostProcessor, Ordered {

	private static final String DYNAMIC_DATASOURCE_KEY = "spring.datasource.dynamic.enabled";

	private static final String DYNAMIC_FILTER_KEY = "spring.datasource.dynamic.druid.proxy-filters[0]";

	private static final String AUTOCONFIGURE_EXCLUDE_KEY = "spring.autoconfigure.exclude";


	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
		environment.getSystemProperties().put(DYNAMIC_DATASOURCE_KEY, "false");
		environment.getSystemProperties().put(DYNAMIC_FILTER_KEY, "sqlLogInterceptor");
		environment.getSystemProperties().put(AUTOCONFIGURE_EXCLUDE_KEY, "com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure");
	}

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE;
	}
}
